package com.ligongmusic.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment{
	protected View rootView;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = layoutInflater(inflater, container, savedInstanceState);
//		changeTop();
		initView();
		return rootView;
	}
	
//	@Override
//	public void setUserVisibleHint(boolean isVisibleToUser) {
//		super.setUserVisibleHint(isVisibleToUser);
//		if (isVisibleToUser) {
//            //相当于Fragment的onResume
//			if(rootView != null)
//				getData();
//        } else {
//            //相当于Fragment的onPause
//        }
//	}
	
//	@Override
//	public void onActivityCreated(Bundle savedInstanceState) {
//		super.onActivityCreated(savedInstanceState);
//		if(rootView == null)
//			getData();// 获取数据
//	}
	
//	protected abstract void changeTop();
	
	/**
	 * 加载布局
	 */
	protected abstract View layoutInflater(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
	
	protected abstract void getData();
	
	protected abstract void initView();
	
	@SuppressWarnings("unchecked")
	protected <T> T getView(int id){
		return (T) rootView.findViewById(id);
	}
	
}
